import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-extend-query',
  templateUrl: './extend-query.component.html',
  styleUrls: ['./extend-query.component.scss']
})
export class ExtendQueryComponent implements OnInit {
  public accountList = [];
  
  public listCount = 10;

  constructor() { }

  ngOnInit() {
    //  账户编码、账户名称、运作日期、开始日期、到期日期、原到期日期、创建日期 
    this.accountList = [];
    let name = ['平安证券对冲1号','华泰证券对冲1号','谢子键']
    let rundate = ['2016-03-03','2016-11-26','2016-03-20'];
    let startdate = ['2016-04-05','2016-05-01','2016-11-30'];
    let enddate = ['2017-01-01','2016-12-30','2016-11-30'];
    let oldEndDate = ['2016-10-25','2016-11-25','2016-12-25'];
    let createDate = ['2016-03-01','2016-02-14','2016-04-30'];
    for (var i = 1; i <= this.listCount; i++) {
      var random = Math.round(Math.random() * 2);
      this.accountList.push({
        // 账户编码、账户名称、运作日期、开始日期、到期日期
        code: '802173' + i,
        name: name[random],
        rundate:rundate[random],
        startdate:startdate[random],
        enddate:enddate[random],
        oldEndDate:oldEndDate[random],
        createDate:createDate[random]

      });
    }
  }
  ngAfterViewInit() {
    //Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
    //Add 'implements AfterViewInit' to the class.
    window['$']('input').iCheck({
      checkboxClass: 'icheckbox_flat-blue',
      radioClass: 'iradio_flat-blue'
    });
    //全选、全反选
    window['$']('#checkAll').on('ifChecked ifUnchecked', function (event) {
      if (event.type == 'ifChecked') {
        window['$']('.subcb').iCheck('check');
      } else {
        window['$']('.subcb').iCheck('uncheck');
      }
    });

    window['$']('.subcb').on('ifChanged', function (event) {
      if (window['$']('.subcb').filter(':checked').length == window['$']('.subcb').length) {
        window['$']('#checkAll').prop('checked', 'checked');
      } else {
        window['$']('#checkAll').prop('checked', false);
      }
      window['$']('#checkAll').iCheck('update');
    });
  }
}
